<?php

//error_reporting(0);
$root = $_SERVER['DOCUMENT_ROOT'];

require_once $root . '/src/php/Utils.php';
require_once $root . '/src/php/Config.php';

// 获取一系列请求参数
$rq = PUtil::getParams(array('path', 'file_name', 'index', 'title', 'title_tip', 'title_desc', 'arguments', 'arguments_name', 'arguments_desc',
            'attributes', 'attributes_name', 'attributes_desc', 'methods', 'methods_name', 'methods_desc', 'return', 'return_desc', 'code'));
$data = array(
    'p_path' => $rq['path'],
    'p_filename' => $rq['file_name'] . '_draft',
    'p_index' => $rq['index'],
    'p_title' => $rq['title'],
    'p_titletip' => $rq['title_tip'],
    'p_titledesc' => $rq['title_desc'],
    'p_arguments' => $rq['arguments'],
    'p_argumentsdesc' => PUtil::disposeList($rq['arguments_name'], $rq['arguments_desc']),
    'p_attributes' => $rq['attributes'],
    'p_attributesdesc' => PUtil::disposeList($rq['attributes_name'], $rq['attributes_desc']),
    'p_methods' => $rq['methods'],
    'p_methodsdesc' => PUtil::disposeList($rq['methods_name'], $rq['methods_desc']),
    'p_return' => $rq['return'],
    'p_returndesc' => $rq['return_desc'],
    'p_code' => addslashes($rq['code']),
);

if (PUtil::saveDoc(PConfig::$tablecn[$rq['path']], $data, 'p_filename="' . $data['p_filename'] . '"')) {
    echo json_encode(array(
        'ret' => 0,
        'msg' => 'Success!',
    ));
} else {
    echo json_encode(array(
        'ret' => -1,
        'msg' => 'Failure!',
    ));
}